﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace OpenQuarters.WebQuarters.Core
{
    public partial class UserMessage : CMSEntity<UserMessage, long>
    {
        [Newtonsoft.Json.JsonProperty]
        public long json_MessageId
        {
            get { return this.MessageId; }
        }

        [Newtonsoft.Json.JsonProperty]
        public bool json_Read
        {
            get { return this.Read; }
        }

        [Newtonsoft.Json.JsonProperty]
        public string json_Category
        {
            get { return this.Category; }
        }

        [Newtonsoft.Json.JsonProperty]
        public string json_Tags
        {
            get { return this.Tags; }
        }

        [Newtonsoft.Json.JsonProperty]
        public string json_Subject
        {
            get { return this.Subject; }
        }

        [Newtonsoft.Json.JsonProperty]
        public string json_Body
        {
            get { return this.Body; }
        }

        [Newtonsoft.Json.JsonProperty]
        public string json_From
        {
            get { return this.From; }
        }

        [Newtonsoft.Json.JsonProperty]
        public string json_FromName
        {
            get { return this.FromName; }
        }

        [Newtonsoft.Json.JsonProperty]
        public string json_DateCreated
        {
            get { return this.DateCreated.HasValue ? this.DateCreated.Value.ToString("f") : DateTime.UtcNow.ToString("f"); }
        }

        [Newtonsoft.Json.JsonProperty]
        public WorkflowItem json_WorkflowItem
        {
            get { return this.WorkflowItem; }
        }

        public override void OnSaving()
        {
            base.OnSaving();
            this.LoggingMode = LoggingMode.Off;

            if (this.Tags == null)
            {
                this.Tags = "";
            }
            if (this.Category == null)
            {
                this.Category = "";
            }
            if (this.DateCreated == null)
            {
                this.DateCreated = DateTime.UtcNow;
            }
        }

        public override System.Linq.Expressions.Expression<Func<UserMessage, bool>> GetIDSelector(long ID)
        {
            return e => e.MessageId == ID;
        }

        public override long GetKey(UserMessage Entity)
        {
            return Entity.MessageId;
        }
    }
}
